package com.testapp.bluetoothtest08.Util;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;


import com.testapp.bluetoothtest08.Constant.Constants;
import com.testapp.bluetoothtest08.File.Token;
import com.testapp.bluetoothtest08.File.UserName;
import com.testapp.bluetoothtest08.MainActivity;



public class AppUtil {
    Intent intent = null;
    public static Activity scanForActivity(Context cont) {
        if (cont == null)
            return null;
        else if (cont instanceof Activity)
            return (Activity)cont;
        else if (cont instanceof ContextWrapper)
            return scanForActivity(((ContextWrapper)cont).getBaseContext());

        return null;
    }

    public void logout(Context context){
        System.out.println("进入logout");
        context=scanForActivity(context);
        intent = new Intent();
        intent.setClass(context, MainActivity.class);
        //token设置为空
        new Token().write("");
        //username清空
        new UserName().write("");
        Constants.login = false;
        context.startActivity(intent);
        ((Activity) context).finish();
    }


}
